﻿using System;
using System.Windows.Forms;
using LevelEditor.Document;

namespace LevelEditor.Forms
{
    public partial class TileSetDialog : Form
    {
        public TileSet TileSet { get; set; }

        public TileSetDialog(TileSet tileSet)
        {
            InitializeComponent();
            toolTip.SetToolTip(tileSetImageTB, "Filename of image to use for the tileset.");
            toolTip.SetToolTip(resourceNameTB, "A name other than the filename used to identify the tileset; mainly used for XNA or similar frameworks. Can be left blank.");
            if (tileSet == null)
            {
                TileSet = new TileSet();
                TileSet.LoadDefaults();
            }
            else
            {
                TileSet = tileSet;
            }
            tileSetImageTB.Text = TileSet.ImageFileName;
            resourceNameTB.Text = TileSet.ResourceName;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            TileSet.ImageFileName = tileSetImageTB.Text;
            TileSet.ResourceName = resourceNameTB.Text;
            DialogResult = DialogResult.OK;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void browseButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.DefaultExt = "png";
            ofd.Filter = "Image Files(*.BMP;*.JPG;*.JPEG;*.GIF;*.PNG)|*.BMP;*.JPG;*.JPEG;*.GIF;*.PNG|All files (*.*)|*.*";
            DialogResult dr = ofd.ShowDialog(this);
            if (dr == DialogResult.OK)
            {
                tileSetImageTB.Text = ofd.FileName;
            }
            ofd.Dispose();
        }
    }
}
